package com.zqx.contextstatechange.context;

import com.zqx.contextstatechange.abstractstate.ScreenState;
import com.zqx.contextstatechange.concretestate.LargerState;
import com.zqx.contextstatechange.concretestate.LargerstState;
import com.zqx.contextstatechange.concretestate.NormalState;
import lombok.extern.slf4j.Slf4j;

/**
 * description: 环境类：此模式下当前类充当了状态管理类 一定程度上违背了开闭原则
 * @author zqx
 * @date 2018/09/06
 */
@Slf4j
public class Screen {

    //枚举
    private ScreenState currentState,normalState,largerState,largestState;

    public Screen() {
        this.normalState = new NormalState();//创建正常状态的对象
        this.largerState = new LargerState();//创建二倍放大状态对象
        this.largestState = new LargerstState();//创建四倍放大状态对象
        this.currentState = normalState;//设置初始状态
        this.currentState.display();
        log.info("【实例化输出】");
    }

    public void setState(ScreenState state){
        this.currentState = state;
    }

    //单击事件处理方法，封装了对状态类中业务方法的调用和状态的转换
    public void onClick(){
        if(this.currentState == normalState){
            this.setState(largerState);
            this.currentState.display();
        }else if(this.currentState == largerState){
            this.setState(largestState);
            this.currentState.display();
        }else if(this.currentState == largestState){
            this.setState(normalState);
            this.currentState.display();
        }
    }
}
